//
//  AppImageActivityView.swift
//  XiaoweHearingAid
//
//  Created by Riven on 2023/4/13.
//

import UIKit

class AppImageActivityView: UIImageView {
    
    override var isAnimating: Bool {
        return _isAnimating
    }
    
    private var _isAnimating: Bool = false

    override func startAnimating() {
//        if let _ = layer.animation(forKey: "transform_rotation") {
//            return
//        }
        if isHidden {
            stopAnimating()
            return
        }
        
        if _isAnimating {
            return
        }
        
        _isAnimating = true
        let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation")
        rotateAnimation.toValue = Double.pi * 2
        rotateAnimation.duration = 1
        rotateAnimation.repeatCount = .infinity
        rotateAnimation.isRemovedOnCompletion = false
        layer.add(rotateAnimation, forKey: "transform_rotation")
    }
    
    override func stopAnimating() {
        _isAnimating = false
        layer.removeAllAnimations()
    }

}
